//
//  ETViewController.m
//  Yuexiaowen
//
//  Created by YueWen on 2017/3/24.
//  Copyright © 2017年 YueWen. All rights reserved.
//

#import "NWViewController.h"


@interface NWViewController ()
@end


@implementation NWViewController

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return self.statusBarStyle; 
}


- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle
{
    if (_statusBarStyle != statusBarStyle) {
        
        _statusBarStyle = statusBarStyle;
        [self setNeedsStatusBarAppearanceUpdate];
    }
}


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.hidesBottomBarWhenPushed = true;
        [self loadPropertysAtInitialization];
        
//        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-150, 0) forBarMetrics:UIBarMetricsDefault];
//        [[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:5 forBarMetrics:UIBarMetricsDefault];
    }
    
    return self;
}


- (void)actionBackItemInNavigationBar
{
    if (self.navigationController) {
        [self.navigationController popViewControllerAnimated:true];
    }else {
        [self dismissViewControllerAnimated:true completion:nil];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    if (RITL_iOS_Version_GreaterThanOrEqualTo(11.0)) {
    
        if (@available(iOS 11.0,*)) {
            self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
        }
    }
    
    if (self.hasParentNavigationController) {//设置导航
        
        UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
        
        self.navigationItem.backBarButtonItem = barButtonItem;
        
        [self.navigationController.navigationBar setBackIndicatorImage:self.backIndicatorImage.ritl_image.ritl_renderOriginImage ];
        
        [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:self.backIndicatorImage.ritl_image.ritl_renderOriginImage];

        [self setDefaultNavigationBarWhenHasParentNavigationController];
    }
}


- (void)nav_back {
    [self.navigationController popViewControllerAnimated:true];
}



-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    printf("I am %s\n",NSStringFromClass(self.class).UTF8String);
}


-(void)loadPropertysAtInitialization
{
    self.archiverManager = [RITLArchiverManager new];
    self.archiverManagerDocument = nil;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    NSLog(@"\n\n[dealloc] [%@]\n\n",NSStringFromClass([self class]));
}


-(void)doNothing
{
    
}


- (void)configRequestAPI
{
    
}



- (BOOL)startArchiver:(NSArray<id<NSCoding>> *)archiverObjects
{
    if (!archiverObjects || !self.archiverManagerDocument) {
        return false;
    }
    
    return [self.archiverManager ritl_startArchiver:archiverObjects document:self.archiverManagerDocument error:nil];
}

- (NSArray<id<NSCoding>> *)readArchiverObjects
{
    if (!self.archiverManagerDocument) {
        return @[];
    }
    
    return [self.archiverManager ritl_readArchiverObjectsInDocument:self.archiverManagerDocument];
}

- (void)elementDidClick:(id)sender
{
    
}


#pragma mark - NavigationBar

- (BOOL)hasParentNavigationController
{
    return [self.parentViewController isKindOfClass:[UINavigationController class]];
}

- (NSString *)backIndicatorImage
{
    return @"nav_back_default";
}

#pragma mark - Autorotate

- (BOOL)shouldAutorotate
{
    return false;
}


- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

@end



